package com.itheima.demo5;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class IODemo7 {
    public static void main(String[] args) throws IOException {
        File src = new File("C:\\Users\\DZL\\Desktop\\c");

        File dest = new File("C:\\Users\\DZL\\Desktop\\b");

        copydir(src,dest);


    }


    private static void  copydir(File src , File dest) throws IOException {
        dest.mkdirs();

        File[] files = src.listFiles();
        //遍历数组
        for (File file : files) {
            //判断是否为文件
            if (file.isFile()){
                //进行拷贝
                FileInputStream fileInputStream = new FileInputStream(file);
                FileOutputStream fileOutputStream = new FileOutputStream(new File(dest,file.getName()));
                byte[] bytes = new byte[1024];
                int len;
                while ((len = fileInputStream.read(bytes)) != -1){
                    fileOutputStream.write(bytes,0,len);
                }
                fileInputStream.close();
                fileOutputStream.close();
            }else {
                //进行递归
                copydir(file,new File(dest,file.getName()));

            }
        }
    }

}
